<%@page contentType="text/html; charset=utf-8"%>
<%@page import="git.bankview.sl.schedule.PipelineFactory,java.sql.Date,java.text.SimpleDateFormat
				,java.util.Calendar,java.util.ArrayList,java.util.List,java.text.ParseException" %>
<%@page import="com.git.accessimp.DealParameterMdb"%>

<html>
<head>
<link rel="stylesheet" href="/bi/css1/default.css" type="text/css">
<title>Access sql execute result page</title>
</head>
<body>
<table id="headTable" border="0" width="100%" cellspacing="0" cellpadding="0" class="dialogHeader" style="height:28px;" >
	<tr>
		<td id="titleContainer" class="dialogHeaderTitle" style="width:100%;padding-left:10px;">
		<font size="2px">资产后台脚本执行结果页面</font></td>
    </tr>
</table>
<h2>Sql 脚本执行结束！</h2>
<% 
	
	/*
	*@14010 源数据的备份加载
	*@54010 投资资产多维统计表
	*@54011 金融资产减值准备变动表
	*@54012 委托资产资金流水表
	*@54013 银行存款情况表
	*@54014 定期存款流水表
	*/
	int[] taskIdArray ={14010,54010,54011,54012,54013,54014,54015};
	String[] taskIdDesc ={"源数据的备份加载","投资资产多维统计表","金融资产减值准备变动表","委托资产资金流水表"
							,"银行存款情况表","定期存款流水表","资产报表优化"};
	
	String resultStr = "";
	List<String> resultList = new ArrayList<String>();
	
	//add 2011-5-9 
	StringBuffer sBuffer = new StringBuffer(); //记录后台脚本执行信息
	DealParameterMdb db = new DealParameterMdb();
	String impDate = new java.text.SimpleDateFormat("yyyyMMdd").format(new java.util.Date()); //导入日期
	char impType = 'D'; //导入类型 Access 后台调度脚本
	char impStatus = '0'; //导入状态标识 0 成功 1 有异常存在 
	java.util.Date startTime = null;  //shell job run start time
	java.util.Date endTime = null;    //shell job run end time
	
	
	String beginDataStr = request.getParameter("beginDataDate");
	String endDataStr = request.getParameter("endDataDate");
	sBuffer.append("{beginDate==="+beginDataStr+" endDate==="+endDataStr+"}");
	
	SimpleDateFormat parseTime = new SimpleDateFormat("yyyy-MM-dd");
	java.util.Date beginDate = null;
	java.util.Date endDate = null;
	try{
		beginDate = parseTime.parse(beginDataStr);
		endDate = parseTime.parse(endDataStr);
	}catch(ParseException e){
		e.printStackTrace();
	}
	Calendar calendarBegin = Calendar.getInstance();
	calendarBegin.setTime(beginDate);
	
	Calendar calendarEnd = Calendar.getInstance();
	calendarEnd.setTime(endDate);
	
	//如果开始日期大于截止日期，则退出
	if(calendarBegin.compareTo(calendarEnd) > 0){
		out.println("开始日期大于截止日期，退出；请检查！！！"+"<br>");
		return;
	}
	
	startTime = new java.util.Date();  //2011-5-10
	
	//如果开始日期与截止日期为同一天
	if(calendarBegin.compareTo(calendarEnd) == 0){
		out.println("开始日期等于截止日期！"+"<br>");
	
		for(int i=0; i < taskIdArray.length; i++){
			try{
				resultStr = PipelineFactory.runTaskById(taskIdArray[i],Date.valueOf(beginDataStr));
			}catch(Exception e){
				impStatus = '1';
				sBuffer.append("#任务{"+taskIdArray[i]+"}"+taskIdDesc[i]+" 执行过程出现错误，异常：-->"+e.getMessage());
			}
			
 			resultList.add(taskIdDesc[i]+"-->"+resultStr);
 			sBuffer.append("#"+taskIdDesc[i]+"-->"+resultStr);
		}
		
	}
	
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	String dayStr = "";
	
	//如果开始日期小于截止日期，则循环
	if(calendarBegin.compareTo(calendarEnd) <0){
		out.println("开始日期小于截止日期！"+"<br>");
		while(calendarBegin.compareTo(calendarEnd) <= 0 ){
			dayStr = sdf.format(calendarBegin.getTime());
			resultList.add("执行日期-->"+dayStr);
			sBuffer.append("#"+"执行日期-->"+dayStr);
			
			for(int i=0; i < taskIdArray.length; i++){
				try{
					resultStr = PipelineFactory.runTaskById(taskIdArray[i],Date.valueOf(dayStr));
					resultList.add(taskIdDesc[i]+"-->"+resultStr);
 					sBuffer.append("#"+taskIdDesc[i]+"-->"+resultStr);
				}catch(Exception e){
					impStatus = '1';
					sBuffer.append("#任务{"+taskIdArray[i]+"} "+taskIdDesc[i]+" 执行过程出现错误，异常：-->"+e.getMessage());
				}
			
 			
			}
			calendarBegin.add(Calendar.DAY_OF_MONTH,1);
		}
	}
	
	endTime = new java.util.Date(); //2011-5-10
	
	//输出调用结果语句
	for(int i=0; i<resultList.size(); i++){
 		out.println(resultList.get(i)+"<br>");
    }
    
    //2011-5-9
    sBuffer.append("#脚本任务调度结束！");
    String content = sBuffer.toString();
    db.impExeSheetResult(impDate,impType,startTime,endTime,impStatus,content);
    sBuffer = null; //释放内存 2011-5-9
    
	out.println("<h2>脚本任务调度结束！！</h2>"+"<br>");
%>
<table border="0" width="100%" cellpadding="1" cellspacing="0" class="dialogButtonBar" id="FooterContainer" style="margin-top:20px;height:50px;">	
	<tr>
		<td nowrap class="copyright" id="LegalContainer">技术支持 Git;高伟达软件技术有限公司</td>
	</tr>
</table>
</body>
</html>